<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="strutsTags"%>
<%@taglib prefix="ty" uri="/wyzzTags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<head>
	<base href="<%=basePath%>">
	<title>刷卡管理</title>
	<jsp:include flush="true" page="/sitemesh/jsPackage.jsp"></jsp:include>
	<link href="<s:url value="/resource/css/style.css"/>" rel="stylesheet"
		type="text/css" />
	<script type='text/javascript' src='dwr/interface/OrgMapAction.js'></script>
	<script type='text/javascript'
		src='dwr/interface/DwrSyncAttdMachine.js'></script>
	<script type='text/javascript' src='dwr/interface/DwrForAttend.js'></script>
	<script type="text/javascript"
		src="dwr/interface/OriginalDataImportShowAction.js"></script>
	<s:head />
</head>
<body onload="hrm.common.check_order();">
	<span class="errorMessage" id="message"></span>
	<s:component template="bodyhead">
		<s:param name="pagetitle" value="'刷卡管理'" />
	</s:component>

	<s:form id="originalDataShow" name="originalDataShow"
		action="originalDataImportShow" namespace="/examin" method="POST">
		<!-- 隐藏字段 -->
		<s:hidden name="aodIds"></s:hidden>
		<s:hidden name="iodefId"></s:hidden>
		<s:hidden id="order" name="page.order" />
		<s:hidden id="operate" name="page.operate" />
		<s:hidden id="page.currentPage" name="page.currentPage" />
		<table width="100%" class="formtable">
			<tr>
				<td>
					<table width="100%">
						<tr>
							<td align="right">
								员工:
							</td>
							<td>
								<s:textfield id="emp" name="searchBean.attdEmp.empName"
									size="16" maxlength="64" />
							</td>
							<td align="right">
								刷卡日期:
							</td>
							<td>
								<input id="startDate"
									value=<s:date name="searchBean.startDate"
									format="yyyy-MM-dd" />
									name="searchBean.startDate" required="true" size="10"
									maxlength="10" />
								<img onclick="WdatePicker({el:'startDate'})" class="dateimg"
									src="resource/js/My97DatePicker/skin/datePicker.gif">
								到
								<input id="endDate"
									value=<s:date name="searchBean.endDate" format="yyyy-MM-dd" />
									name="searchBean.endDate" required="true" size="10"
									maxlength="10" />
								<img onclick="WdatePicker({el:'endDate'})" class="dateimg"
									src="resource/js/My97DatePicker/skin/datePicker.gif">
							</td>
							<td align="right">
								时间段:
							</td>
							<td>
								<s:select id="beginHour" name="searchBean.beginHour"
									list="@com.wyzz.hr.vo.Hours@getHourandHalfList_24()"
									listKey="hourHalf" listValue="description" required="true"
									emptyOption="false" required="true" />
								到
								<s:select id="endHour" name="searchBean.endHour"
									list="@com.wyzz.hr.vo.Hours@getHourandHalfList_24()"
									listKey="hourHalf" listValue="description" required="true"
									emptyOption="false" required="true" />
							</td>
						</tr>
						<tr>
							<td align="right">
								组织单元:
							</td>
							<td>
								<s:orgselector id="orgselector1"
									name="searchBean.attdEmp.empDeptNo.departmentName"
									hiddenFieldName="searchBean.attdEmp.empDeptNo.id" />
							</td>
							<td align="right">
								考勤机号:
							</td>
							<td>
								<s:select name="searchBean.aodTtdMachineNo" list="machineList"
									listKey="macNo" listValue="macNo" multiple="false"
									emptyOption="true" value="searchBean.aodTtdMachineNo" size="1"
									cssStyle="width:85px" />
								备注:
								<s:textfield id="searchBean.aodMemo" name="searchBean.aodMemo"
									size="12" maxlength="64" />
							</td>
							<td align="right">
								班次:
							</td>
							<td>
								<s:select id="searchBean.aodNightStatus"
									name="searchBean.aodNightStatus"
									list="#{'':'全部','0':'白班','1':'夜班'}" emptyOption="false" />
								种类:
								<s:select id="status" name="searchBean.aodStatus"
									value="searchBean.aodStatus"
									list="#{'':'全部','0':'导入','1':'补卡','2':'同步'}"
									emptyOption="false" />
							</td>
						</tr>
					</table>
				</td>
				<td>
					<input title="[Alt+F]" accesskey="F" name="searchData"
						class="button" type="button" value="查询"
						onclick="searchOriginalData();" />
					<input title="[Alt+C]" accesskey="C" name="clear_button"
						class="button" type="button" value="重置"
						onClick="window.location='originalDataImportShow.action';">
				</td>
			</tr>
		</table>

		<!-- 操作 -->
		<div class="operatediv">
			<span class="operatedivleft"> <ty:auth auths="421">
					<input class="button" type="button" value="同步刷卡记录"
						onclick="empSelecotr('batchRead');" />
				</ty:auth> <ty:auth auths="401">
					<input class="button" type="button"
						onclick="initDivImmUpload('IExaminCardData', '');" value="数据导入" />
					<input class="button" type="button" value="人工补卡"
						onclick="empSelecotr('addCard');" />
				</ty:auth> <ty:auth auths="401">
					<input class="button" type="button" value="夜班调整"
						onclick="showChangeNightShift();" />
					<input class="button" type="button" name="deleteData" value="数据清理"
						onclick="deleteOriginalData();" />
				</ty:auth> </span>
			<span class="operatedivright">本次查询共得到<s:property
					value="page.totalRows" />条刷卡记录</span>
		</div>

		<table width="100%" border="0" cellspacing="0" cellpadding="0"
			id="dataTable" class="gridtableList">
			<tr>
				<th align="center">
					<input id="id_check_all" name='dataIds' class="checkbox"
						type="checkbox"
						onclick="hrm.common.checkAllByName('dataIds','id_check_all');"
						value="0">
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('emp.empDistinctNo','originalDataShow');">
						员工编号</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='emp.empDistinctNo_img'>
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('emp.empName','originalDataShow');">
						姓名</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='emp.empName_img'>
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('emp.empDeptNo','originalDataShow');">
						部门</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='emp.empDeptNo_img'>
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('aodAttdDate','originalDataShow');">
						考勤日期</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='aodAttdDate_img'>
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('aodCardTime','originalDataShow');">
						刷卡时间</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='aodCardTime_img'>
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('aodTtdMachineNo','originalDataShow');">
						考勤机号</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='aodTtdMachineNo_img'>
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('aodStatus','originalDataShow');">
						状态</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='aodStatus_img'>
				</th>
				<th nowrap="nowrap">
					<a href="#"
						onclick="hrm.common.order_submit('aodMemo','originalDataShow');">
						备注</a>
					<img src='resource/images/arrow_.gif' width='8' height='10'
						id='aodMemo_img'>
				</th>
				<th nowrap="nowrap">
					班次类型
				</th>
				<th nowrap="nowrap">
					操作
				</th>
			</tr>
			<s:if test="!originalDataList.isEmpty()">
				<!--判断是否为空-->
				<s:iterator value="originalDataList" status="st">
					<tr>
						<td align="center" width="3%">
							<input type="checkbox" class="checkbox"
								id="checkbox<s:property value='aodId'/>" name='dataIds'
								value="<s:property value='aodId'/>" />
						</td>
						<td id="aodEmpDistinctNo<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:property value="attdEmp.empDistinctNo" />
						</td>
						<td id="aodEmpName<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:property value="attdEmp.empName" />
						</td>
						<td id="aodEmpDept<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:property value="attdEmp.empDeptNo.departmentName" />
						</td>

						<td id="aodAttdDate<s:property value="aodId"/>" align="center">
							&nbsp;
							<s:property value="aodAttdDate" />
						</td>
						<td id="aodCardTime<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:date name="aodCardTime" format="yyyy-MM-dd HH:mm:ss" />
						</td>
						<td id="aodTtdMachineNo<s:property value="#st.count"/>"
							align="center">
							&nbsp;
							<s:property value="aodTtdMachineNo" />
						</td>
						<td id="aodStatus<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:if test="aodStatus==0">
						   导入
						</s:if>
							<s:elseif test="aodStatus==1">
						    补卡
						</s:elseif>
							<s:else>
						   同步
						</s:else>
						</td>
						<td id="aodMemo<s:property value="#st.count"/>" align="center">
							&nbsp;
							<s:property value="aodMemo" />
						</td>
						<td id="aodNightShift<s:property value="aodId"/>" align="center">
							<s:if test="checkDateAndCardTime(aodAttdDate, aodCardTime) == 0">
								<img
									onclick="oneChangeNightShift('<s:property value="aodId"/>', 1)"
									id="img<s:property value="aodId"/>" alt="白班" title="白班"
									class="urlimg" src='resource/images/shiftSun.png' />
							</s:if>
							<s:else>
								<img
									onclick="oneChangeNightShift('<s:property value="aodId"/>', 0)"
									id="img<s:property value="aodId"/>" alt="夜班" title="夜班"
									class="urlimg" src='resource/images/shiftMoon.png' />
							</s:else>
						</td>
						<td align="center"
							id="dataOperatin<s:property value="#st.count"/>" align="center">
							<s:if test="aodId!=null&&aodId!=''">
								<img onclick="deleteOneData('<s:property value="aodId"/>')"
									alt='删除' title='删除' class="urlimg"
									src="resource/images/deletesalaryconf.gif" />
							</s:if>
						</td>
					</tr>
				</s:iterator>
			</s:if>
			<s:else>
				<tr>
					<td align="center" colspan="17">
						无符合条件的考勤机刷卡数据！
					</td>
				</tr>
			</s:else>
		</table>
		<s:pager end="page.end" pageNo="page.currentPage"
			totalRows="page.totalRows" totalPages="page.totalPages"
			formId="originalDataShow" start="page.start" />
	</s:form>

	<!-- 夜班调整弹出框 -->
	<div id="dlgChangeNightShift" style="width: 330; display: none;">
		<table cellSpacing="0" cellPadding="0" width="100%" class="listView"
			width="100%">
			<tr>
				<td rowspan="2" width="50%" valign="middle">
					请选择调整类型:
				</td>
				<td align="left">
					<s:hidden id="nightshifttype" name="nightshifttype" />
					<input type="radio" class="radio" name="changeType"
						id="changeType0" value="0" checked="checked"
						onclick="changeType(0);" />
					调整为白班
				</td>
			</tr>
			<tr>
				<td align="left">
					<input type="radio" class="radio" name="changeType"
						id="changeType1" value="1" onclick="changeType(1);" />
					调整为夜班
				</td>
			</tr>
			<tr>
				<td>
					&nbsp;
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2">
					<input id="subBution" class="button" type="button"
						onclick="batchChangeNightShift();" value="确定">
					<input class="button" type="button"
						onclick="hrm.common.closeDialog('dlgChangeNightShift');"
						value="取消">
				</td>
			</tr>
		</table>
	</div>

	<div id="dlgEmpListDiv" title="用户选择列表">
		<jsp:include flush="true" page="../examin/attdOperate.jsp"></jsp:include>
	</div>
	<script type="text/javascript" language="javascript">
	hrm.common.initDialog("dlgChangeNightShift", 560);

	//查询方法(点击查询按钮)
	function searchOriginalData() {
		var startDate = document.originalDataShow.startDate.value;
		var endDate = document.originalDataShow.endDate.value;
		if (startDate.trim() == '') {
			alert("请选择开始日期！");
			return;
		}
		if (endDate.trim() == '') {
			alert("请选择结束日期！");
			return;
		}

		// 开始日期大于结束日期；
		if (startDate > endDate) {
			alert("开始日期大于结束日期！");
			return;
		}

		var beginHour = document.getElementById("beginHour").value;
		var endHour = document.getElementById("endHour").value;
		if (parseFloat(beginHour) >= parseFloat(endHour)) {
			alert("开始时间点大于或等于结束时间点！");
			return;
		}

		document.forms[0].submit();//提交表单
	}

	//数据清理操作(点击清理按钮)
	function deleteOriginalData() {
		var checkBoxs = document.getElementsByName('dataIds');
		var ids = "";
		for ( var i = 1; i < checkBoxs.length; i++) {
			if (checkBoxs[i].checked && checkBoxs[i].checked == true) {
				flag = 1;
				ids += "'" + checkBoxs[i].value + "',";
			}
		}
		ids = ids.substring(0, ids.length - 1);

		if (ids.length == 0) {
			alert("请选择要删除的数据！");
			return;
		}

		if (confirm("确定要删除选中的刷卡数据吗？")) { //confirm确认是否删除
			document.all.aodIds.value = ids;
			document.all.operate.value = "delete";
			document.getElementById('originalDataShow').action = "deleteOneOriginalData.action";
			document.getElementById('originalDataShow').submit();
			//document.forms[0].submit();
		}
	}

	//删除一条数据
	function deleteOneData(aodId) {
		if (confirm("确定要删除该条数据么？")) {
			document.all.aodIds.value = "'" + aodId + "'";
			document.all.operate.value = "delete";
			document.getElementById('originalDataShow').action = "deleteOneOriginalData.action";
			document.getElementById('originalDataShow').submit();
			//document.forms[0].submit();
		}
	}

	//敲击键盘事件
	function enterDown(event) {
		event = event ? event : (window.event ? window.event : null);
		if (event != null && event.keyCode == 13) {
			searchEmp(document.getElementById('emp_sear_value').value);
			return;
		}
	}

	// 获取选中的数据id字符串；
	function getSelectedIds(checkName) {
		var checkBoxs = document.getElementsByName(checkName);
		var ids = "";
		for ( var i = 1; i < checkBoxs.length; i++) {
			if (checkBoxs[i].checked && checkBoxs[i].checked == true)
				ids += checkBoxs[i].value + ",";
		}
		ids = ids.substring(0, ids.length - 1);

		return ids;
	}

	// 显示调整弹出小窗口；
	function showChangeNightShift() {
		var selectIds = getSelectedIds("dataIds");
		if (selectIds == null || selectIds.length == 0) {
			alert("请至少选择一条记录！");
			return;
		}
		document.getElementById("changeType0").checked = true;
		document.getElementById("nightshifttype").value = 0;
		$("#dlgChangeNightShift").dialog("option", "title", "夜班调整");
		hrm.common.openDialog("dlgChangeNightShift");
	}

	//切换调整类型；
	function changeType(type) {
		document.getElementById("nightshifttype").value = type;
	}

	//单个修改刷卡数据所属的班次；
	function oneChangeNightShift(aodId, type) {
		if (!confirm("您确定要修改当前记录的所属班次吗？"))
			return;
		// 将选中的checkbox置为非选中；
		var obj = document.getElementsByName("dataIds");
		for (i = 0; i < obj.length; i++) {
			if (obj[i].checked == true) {
				obj[i].checked = false;
			}
		}
		// 选中当前记录；
		document.getElementById("checkbox" + aodId).checked = true;

		changeNightShift(aodId, type);
	}

	// 批量修改刷卡数据所属的班次；
	function batchChangeNightShift() {
		var selectIds = getSelectedIds("dataIds");

		if (!confirm("您确定要修改选中记录的所属班次吗？"))
			return;

		var type = document.getElementById("nightshifttype").value;
		changeNightShift(selectIds, type);
		hrm.common.closeDialog("dlgChangeNightShift");
	}

	// DWR：切换刷卡数据所属的班次；
	function changeNightShift(aodIds, type) {
		OriginalDataImportShowAction.changeNightShift(aodIds, type,
				changeCallback);
		function changeCallback(data) {
			// 调整页面数据显示；
			var idArr = aodIds.split(",");
			for ( var i = 0; i < idArr.length; i++) {
				var tempId = idArr[i];
				var imgObj = document.getElementById("img" + tempId);
				// 夜班   白班；
				if (type == 0) {
					imgObj.src = "resource/images/shiftSun.png";
					imgObj.alt = "白班";
					imgObj.title = "白班";
					imgObj.onclick = new Function("oneChangeNightShift('"
							+ tempId + "',1)");
				}
				// 白班   夜班；
				if (type == 1) {
					imgObj.src = "resource/images/shiftMoon.png";
					imgObj.alt = "夜班";
					imgObj.title = "夜班";
					imgObj.onclick = new Function("oneChangeNightShift('"
							+ tempId + "',0)");
				}

				// 重新设置页面显示的考勤日期；
				var aodDate = data[tempId];
				if (aodDate != null && aodDate != undefined) {
					var tdObj = document.getElementById("aodAttdDate" + tempId);
					tdObj.innerHTML = aodDate;
					tdObj.align = "center";
				}
			}

			// 将选中的checkbox置为非选中；
			var obj = document.getElementsByName("dataIds");
			for ( var i = 0; i < obj.length; i++) {
				if (obj[i].checked == true) {
					obj[i].checked = false;
				}
			}

			alert("调整成功！");
		}
	}

	// $('#attdDate').val(hrm.common.getCurrentDate()); //给attdDate赋上当天日期
</script>
	<jsp:include flush="true" page="../io/div_upload.jsp"></jsp:include>
	<jsp:include page="../sitemesh/div_wait.jsp" flush="true"></jsp:include>
</body>
